package com.sigetdriver.controller;

import java.util.ArrayList;
import android.util.Log;
import com.dsbmobile.dsbframework.controller.persistence.Entity;
import com.sigetdriver.entities.NotificacionesBean;

public class NotificacionesController {

	private final String TAG = NotificacionesController.class.getSimpleName();
	public static NotificacionesController instance;

	public static NotificacionesController getInstance() {
		if (instance == null) {
			instance = new NotificacionesController();
		}
		return instance;
	}

	public long storeMessage(NotificacionesBean notificacion) {
		long lResult = -1;

		try {
			lResult = NotificacionesBean.tableHelper.insertEntity(notificacion);
		} catch (Exception e) {
			Log.e(TAG,
					"Mensaje-> " + e.getStackTrace() + " - " + e.getMessage());
		}

		return lResult;
	}
	

	public int deleteMessage(String sCreated_at) {
		int iResult = -1;

		try {
			iResult = NotificacionesBean.tableHelper.deleteEntity(
					NotificacionesBean.CREATED_AT_COLUMN_NAME + "=?",
					new String[] { sCreated_at });
		} catch (Exception e) {
			iResult = 0;
		}
		return iResult;
	}

	
	public ArrayList<NotificacionesBean> getAllMessages() {

		ArrayList<NotificacionesBean> lsNoti = new ArrayList<NotificacionesBean>();
		ArrayList<Entity> entities = NotificacionesBean.tableHelper
				.getEntities(null, null);

		for (Entity entity : entities) {
			lsNoti.add((NotificacionesBean) entity);
		}

		return lsNoti;
	}

	// " ORDER BY " + NotificacionesBean.CREATED_AT_COLUMN_NAME + "ASC"

}
